<!DOCTYPE html>
<html lang="zh-cmn-Hans">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <link rel="stylesheet" href="../../static/assets/css/zpui.css" />
    <link rel="stylesheet" href="../../static/assets/css/all.css" />
    <script src="../../static/assets/js/page.js"></script>
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>

    <title> 我的库存 </title>
</head>

<body>
    <div class="page">
        <div class="page-hd">
            <div class="header bor-1px-b">
                <div class="header-left">
                    <a href="javascript:history.go(-1)" class="left-arrow"></a>
                </div>
                <div class="header-title">我的库存</div>
                <div class="header-right" style="width: 1rem;">
                    <a href="../../user/user/cloudgoods.html">云仓产品</a>
                </div>
            </div>
        </div>

        <div class="page-bd">
            <!-- 页面内容-->
            <div class="weui-cells border-none mt0" style="background-color: #f65236;padding-bottom: 1rem;">
                <div class="weui-cell border-none">
                    <div class="weui-cell__bd text-white">
                        <div class="fs68 font_number">140</div>
                        <div class="fs26 ">总云仓库存</div>
                    </div>
                </div>
            </div>
            <div style="margin-top: -1rem;" class="shop-list">
                <script type="text/html" id="orderTpls">
                    {{each list as item index}}
                    <div class="weui-cells card-box">
                        <div class="weui-cell border-none">
                            <div class="weui-cell__hd">
                                <img src="{{item.goods_thumb}}" class="img140" />
                            </div>
                            <div class="weui-cell__bd">
                                <div class="fs28 ellipsisLn1">{{item.goods_name}}</div>
                                <div style="display: flex">
                                    <div style="margin-right: 0.5rem">
                                        <span class="fs26">当前库存</span>
                                        <span class="fs48 font_number">{{item.inventory}}</span>
                                    </div>
                                    <div>
                                        <span class="fs26">已提货</span>
                                        <span class="fs48 font_number">{{item.number}}</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="weui-cell pt0 border-none">
                             
                            <a href="../../user/user/inventorylog?goods_id={{item.goods_id}}" class="kc_btn mr30">库存明细</a>
                            {{if item.make_status == 1}}<a href="../../user/user/replenishment/goods_id/{{item.goods_id}}" class="kc_btn mr30">补货</a>{{/if}}
                            {{if list.role_id > 4}}<a href="../../user/user/transfer/goods_id/{{item.goods_id}}" class="kc_btn mr30">云仓配货</a>{{/if}}
                            <a href="javascript:;" onclick="addToCart(this,{{item.goods_id}},'onbuy')" class="kc_btn">提货到线下</a>
                            
                        </div>
                    </div>
                    {{/each}}
                </script>
            </div>
        </div>
    </div>
    </div>

    <script src="../../static/assets/js/lib/jquery-2.1.4.js"></script>
    <script src="../../static/assets/js/jquery-weui.min.js"></script>
    <script src="../../static/assets/js/lib/fastclick.js"></script>
    <script src="../../static/tpl/js/art-template.js"></script>
    <script src="../../static/mobile/default/js/page.js"></script>
    <script>
        $(function() {
            FastClick.attach(document.body);
        });
    </script>
    <script>
        var nowPage = [],
            getAgain = [],
            isLoadend = [];
        var _type = "shop-list";

        $(function() {
            getList();
            var get = false;
            // 当用户滚动到页面底部的时候加载更多内容。
            $('.page-bd').infinite(100);
            $('.page-bd').infinite().on("infinite", function() {
                if (get) return;
                getList();
            })
            let role_id = "6";
            //请求列表数据
            function getList(isagain) {
                page = nowPage[_type];
                if (typeof(page) == 'undefined') page = 1;
                if (isLoadend[_type] == true) return false;
                if (isagain == true) {
                    if (getAgain[_type] == false) return false;
                    getAgain[_type] = false;
                } else {
                    $('.' + _type + '').append('<div id="jz" style="margin-bottom:20px;" class="fs24 text-muted mt30 tc">内容加载中~</div>');
                }
                isLoadend[_type] = true;
                $.ajax({
                    url: '/user/userapi/mydepository/p/'+page+'.html', // 跳转到 action
                    data: {},
                    type: 'post',
                    cache: false,
                    headers:{'token': $.cookie('code')},
                            dataType: 'json',
                    success: function(res) {
                        res.list.role_id = role_id;
                        isLoadend[_type] = false;
                        if (res.code == 0) {
                            $.alert(res.errmsg);
                            getAgain[_type] = true;
                            $('.' + _type + '').find('#jz').html('加载失败，点击重新加载.');
                            return false;
                        }
                        nowPage[_type] = page + 1;
                        $('#jz').remove();
                        if (res.list.length > 0) {
                            console.log(res);
                            $('.' + _type + '').append(template('orderTpls', res));
                        } else {
                            $('.' + _type + '').html('<div class="empeyOrder" style="width: 100%;text-align: center;margin-top:1rem;">\
                                <img style = "width: 100%;" src = "/static/mobile/default/images/emptyData.png" alt = "">\
                                <span class="fs24 text-muted tc mt30">暂无记录</span>\
                            </div>');
                        }

                        if (res.page_count == page) {
                            $('.' + _type + '').append('<div id="jz" style="margin-bottom:20px;" class="fs24 text-muted mt30 tc">---我也有底线的---</div>');
                            isLoadend[_type] = true;
                            get = true;
                        }
                    },
                    error: function() {
                        isLoadend[_type] = false;
                        getAgain[_type] = true;
                        $('.' + _type + '').find('#jz').html('加载失败，点击重新加载.');
                    }
                });
            }

        })


        //添加到购物车
        function addToCart(obj, goods_id, type, prom_type = 0, prom_id = 0) {
            var arr = new Object;
            arr.goods_id = goods_id;
            arr.type = type;
            arr.prom_type = prom_type;
            arr.prom_id = prom_id;
            arr.types = 'delivery';
            $.post("/shop/api.flow/addcart.html", arr, function(res) {
                if (res.code == 1) {
                    if (arr.type == 'onbuy') {
                        window.location = '/user/user/takegoods/rec_id/'+res.rec_id+'/goods_id/'+res.goods_id+'.html';
                        return false;
                    }
                    //$('.cartNum').html(res.cartInfo.num);
                }else{
                    $.alert(res.errmsg);
                }
                if (res.code == 2) {
                    if (res.errmsg) $.alert(res.errmsg);
                    return false;
                }
                if (arr.type == 'onbuy') {
                    return;
                }
                if (res.errmsg) $.alert(res.errmsg);
            })

        }
    </script>
</body>

</html>